package collection;

import java.util.ArrayList;
import java.util.List;

public class ListDemo3 {
    public static void main(String[] args) {
        // 创建集合对象<Integer> 存放0~10的整数
        List<Integer> list =new ArrayList<>();
        for (int i=0;i<10;i++){
            list.add(i);
        }
        System.out.println("list:"+list);

        //subList(int fromIndex,int toIndex)
        List<Integer> subList=list.subList(3,7);
        System.out.println("subList:"+subList);
        //将subList中的元素*10
        for (int i=0;i<subList.size();i++){
            subList.set(i,subList.get(i)*10);
        }
        System.out.println("subList:"+subList);//subList:[30, 40, 50, 60,]
        System.out.println("list:"+list);//list:[0,1,2,30, 40, 50, 60, 7, 8,9,10]

        //修改原list集合后，subList也会跟着改变
        list.set(3,1000);
        System.out.println("list:"+list);
        System.out.println("subList:"+subList);
        //删除时候，输出subList会报异常
        list.remove(0);
        //System.out.println("sublist:"+subList);
    }
}
